package org.openmore.consumer.service.feign;

import io.swagger.annotations.ApiParam;
import org.openmore.consumer.dto.common.BaseResponse;
import org.openmore.consumer.dto.common.PermissionDto;
import org.openmore.consumer.service.feignImpl.PermissionServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;


import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@Service
@FeignClient(value = "openmore-opc", fallbackFactory = PermissionServiceImpl.class)
public interface PermissionService {

        /**查询权限列表*/
        @RequestMapping(method = RequestMethod.GET, value = "/api/permission/query")
        public BaseResponse selectAllByPage(
                @RequestParam(required = false, defaultValue = "all") @ApiParam(value = "权限类型：parent表示父权限，为空或all表示所有权限，children表示子权限") String type,
                @RequestParam(required = false) @ApiParam(value = "权限名称") String name,
                @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "分页第几页") Integer pageNum,
                @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "每页多少记录") Integer pageSize);

        /**查询当前用户权限列表*/
        @RequestMapping(method = RequestMethod.GET, value = "/api/permission/tree")
        public BaseResponse getPermissionTree();

        /**根据角色ID查询权限*/
        @RequestMapping(method = RequestMethod.GET, value = "/api/permission/role/{id}")
        public BaseResponse getGrantedPermissionByRole(@PathVariable @ApiParam(required = true, value = "角色id") String id);

        /**根据权限ID查询权限*/
        @RequestMapping(method = RequestMethod.GET, value = "/api/permission/{id}")
        public BaseResponse getPermissionById(@PathVariable @ApiParam(required = true, value = "id") String id);

        /**更改权限*/
        @RequestMapping(method = RequestMethod.PUT, value = "/api/permission")
        public BaseResponse updatePermission(@RequestBody @ApiParam(value = "新Permission信息", required = true) PermissionDto permission);

        /**新建权限*/
        @RequestMapping(method = RequestMethod.POST, value = "/api/permission", consumes = {APPLICATION_JSON_UTF8_VALUE})
        public BaseResponse insertPermission(@RequestBody @ApiParam(value = "创建Permission", required = true) PermissionDto permission);

        /**删除权限*/
        @RequestMapping(method = RequestMethod.DELETE, value = "/api/permission/{id}")
        public BaseResponse deletePermission(@PathVariable @ApiParam(value = "Permissionid", required = true) String id);
}
